#include "qmlsetting.h"
#include <QDebug>

QmlSetting::QmlSetting()
{
}

void QmlSetting::setAppName(QString p_appname){
    qDebug()<<"init de la conf";
    this->innerSetting = new QSettings("KDeadMouse",p_appname,this);
    this->innerSetting->setIniCodec("UTF-8");
}

QVariant QmlSetting::value(QString key){
    return this->innerSetting->value(key);
}

bool QmlSetting::isValue(QString key){
    QVariant v = this->value(key);
    return v.toBool();
}

QVariant QmlSetting::conf(QString key,QVariant defaultValue){
    QVariant res = this->value(key);
    if(res.isNull()){
        qDebug()<<"key:" + key<<" is empty, setting it";
        innerSetting->setValue(key,defaultValue);
        return defaultValue;
    }
    return res;
}


QVariant QmlSetting::validValue(QString key,QVariant defaultValue){
    QVariant res = this->value(key);
    if(res.isNull()){
        qDebug()<<"key:" + key<<" is empty";
        return defaultValue;
    }
    return res;
}

QStringList QmlSetting::getListKeys(QString key){
    innerSetting->beginGroup(key);
    QStringList res = innerSetting->childGroups();
    innerSetting->endGroup();
    qDebug()<<"listkeys:" << res;
    return res;
}


